class Action(object):
    def __init__(self, client):
        self.client = client

class Next(Action):
    def __call__(self):
        self.client.next()


class Prev(Action):
    def __call__(self):
        self.client.previous()


class PlayPause(Action):
    def __call__(self):
        status = self.client.status()
        if status.get('state','stopped') == 'play':
            self.client.pause(1)
        elif status.get('state','stopped') == 'pause':
            self.client.play()
        else:
            self.client.play()


class Stop(Action):
    def __call__(self):
        self.client.stop()


class SetVolume(Action):
    def __call__(self,value):
        self.client.setvol(value)


class PlaylistMoveUp(Action):
    def __init__(self,client,playlist):
        Action.__init__(self,client)
        self.playlist = playlist

    def __call__(self):
        self.playlist.move_selection_up()

class PlaylistMoveDown(Action):
    def __init__(self,client,playlist):
        Action.__init__(self,client)
        self.playlist = playlist

    def __call__(self):
        self.playlist.move_selection_down()


class PlaylistRemove(Action):
    def __init__(self,client,selection):
        Action.__init__(self,client)
        self.selection = selection

    def __call__(self):
        for song in self.selection():
            self.client.deleteid(song.song_id)

class PlaylistClear(Action):
    def __call__(self):
        self.client.clear()

class PlaylistRandomize(Action):
    def __call__(self):
        self.client.shuffle()

class PlaySong(Action):
    def __call__(self, song):
        if song:
            print "Play ", song.song_id
            self.client.seekid(song.song_id, 0)

class ToggleStatus(Action):
    def __init__(self,controller):
        Action.__init__(self,None)
        self.controller = controller

    def __call__(self):
        self.controller.toggle_status()
